package com.ruoyi.labdata.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.college.domain.LabBuidings;
import com.ruoyi.college.service.ILabBuidingsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.labdata.domain.LabClassRoom;
import com.ruoyi.labdata.service.ILabClassRoomService;

/**
 * 实验室地址Controller
 * 
 * @author winner pan
 * @date 2022-02-07
 */
@RestController
@RequestMapping("/labdata/lbroom")
public class LabClassRoomController extends BaseController {
	@Autowired
	private ILabClassRoomService labClassRoomService;
	@Autowired
	private ILabBuidingsService buidingsService;

	/**
	 * 查询实验室地址列表
	 */
	@PreAuthorize("@ss.hasPermi('labdata:lbroom:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabClassRoom labClassRoom) {
		startPage();
		List<LabClassRoom> list = labClassRoomService.selectLabClassRoomList(labClassRoom);
		return getDataTable(list);
	}

	/**
	 * 导出实验室地址列表
	 */
	// @PreAuthorize("@ss.hasPermi('labdata:lbroom:export')")
	/*
	 * @Log(title = "实验室地址", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabClassRoom
	 * labClassRoom) { List<LabClassRoom> list =
	 * labClassRoomService.selectLabClassRoomList(labClassRoom);
	 * ExcelUtil<LabClassRoom> util = new
	 * ExcelUtil<LabClassRoom>(LabClassRoom.class); return
	 * util.exportExcel(list, "lbroom"); }
	 */

	/**
	 * 获取实验室地址详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:lbroom:query')")
	@GetMapping(value = "/{classRoomId}")
	public AjaxResult getInfo(@PathVariable("classRoomId") Long classRoomId) {
		return AjaxResult.success(labClassRoomService.selectLabClassRoomById(classRoomId));
	}

	/**
	 * 新增实验室地址
	 */
	@PreAuthorize("@ss.hasPermi('labdata:lbroom:edit')")
	@Log(title = "实验室地址", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabClassRoom labClassRoom) {
		return toAjax(labClassRoomService.insertLabClassRoom(labClassRoom));
	}

	/**
	 * 修改实验室地址
	 */
	@PreAuthorize("@ss.hasPermi('labdata:lbroom:edit')")
	@Log(title = "实验室地址", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabClassRoom labClassRoom) {
		return toAjax(labClassRoomService.updateLabClassRoom(labClassRoom));
	}

	/**
	 * 删除实验室地址
	 */
	@PreAuthorize("@ss.hasPermi('labdata:lbroom:edit')")
	@Log(title = "实验室地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classRoomIds}")
	public AjaxResult remove(@PathVariable Long[] classRoomIds) {
		return toAjax(labClassRoomService.deleteLabClassRoomByIds(classRoomIds));
	}

	/***
	 * 获取所有的楼栋信息.
	 * 
	 * @return
	 */
	@GetMapping(value = "/allBuilding")
	public AjaxResult getBuildingList(LabBuidings labBuidings) {
		return AjaxResult.success(this.buidingsService.selectLabBuidingsList(labBuidings));
	}
}
